<!DOCTYPE html>
<html>

<head>
    <title>游记列表</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travel.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>

    <script>
        $(function () {
            //查询全部游记
            /* $.get('/travels',function (data) {
                 $('#allTravels').renderValues(data);
             });*/

            //当前页的input框
            var currentInput = $('#currentPage');

            //用于存储游记的数组容器
            var travelArr = [];

            //总页数
            var pages = 1;

            //获取我的游记数据
            function query() {

                //获取当前页的值
                var currentPage = currentInput.val();//1

                $.get('/travels', {currentPage: currentPage}, function (data) {
                    console.log(data);
                    //合并两个数组
                    $.merge(travelArr,data.list);

                    var json = {list:travelArr}//将数组封装成一个json对象,属性名为loop渲染指定的list
                    //重新渲染数据
                    $('#allTravels').renderValues(json,{
                        'getAddress':function(item,value) {
                            var add = $(item).data('href');
                            $(item).attr('href',add+value);
                            //给a元素绑定id值,记录浏览次数时用
                            $(item).attr("data-did",value)
                        }
                    });

                    /*//将返回的数据渲染
                    $('.travels').renderValues(data);*/


                    //从pageInfo中获取总页数,并设置
                    pages = data.pages;

                    //游记浏览次数新增功能
                    $("[name=targetA]").click(function () {
                        //点击时触发浏览次数新增接口
                        $.ajax({
                            url:"/travelsviewcount/"+$(this).data("did"),
                            type:"put"
                        })
                    })

                });

                //当前页input框+1维护,不能用函数内的变量
                currentInput.val(parseInt(currentPage)+1);//字符串记得转成数字
            }

            //默认查询第一页的数据
            query();

            //当页面滚动条变化时,执行的函数
            $(window).scroll(function () {
                if ($(document).scrollTop()+$(window).height()>=$(document).height()){
                    //获取当前页
                    var currentPage = currentInput.val();
                    //判断是否大于最后一页
                    if (currentPage<=pages){
                        query();
                    }else {//最后一页,提示
                        $(document).dialog({
                            type : 'notice',
                            infoText: '到底',
                            autoClose: 1500,
                            position: 'center'  // center: 居中; bottom: 底部
                        });
                    }
                }
            });

            //获取3条每周推荐
            $.get('/travels/commends',{type:2,pageSize:3},function (data) {
                $('#travelsCommends').renderValues(data,{
                    'getAddress':function(item,value) {
                        var add = $(item).data('href');
                        $(item).attr('href',add+value);
                    }
                });
                //为第一个item设置active
                $(".carousel-item:first").addClass("active");
            });
        });
    </script>
</head>

<body>


<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="搜游记">
            </div>
        </div>
    </div>
</div>
<input type="hidden" name="currentPage" id="currentPage" value="1"/>


<div class="container">

    <h6>每月冠军游记</h6>
    <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
        <div id="travelsCommends" class="carousel-inner">
            <div render-loop="list">
                <div class="carousel-item">
                    <div class="border commend">
                        <a data-href="travelContent.html?id=" render-key="list.travel_id" render-fun="getAddress">
                            <img render-src="list.coverUrl" width="100%" height="200px">
                            <h1 render-html="list.title"></h1>
                            <small render-html="list.subTitle"></small>
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
    </div>
</div>

<div class="container">
    <h6>全部游记</h6>
    <div id="allTravels">
        <div render-loop="list">
            <div class="row detail">
                <div class="col">
                    <a name="targetA" data-href="travelContent.html?id=" render-key="list.id" render-fun="getAddress">
                        <h4 render-html="list.title"></h4>
                    </a>
                    <p>
                        <a  data-href="userProfiles.html?id=" render-key="list.author.id" render-fun="getAddress">
                        <img class="rounded-circle head-img" render-src="list.author.headImgUrl">
                            <span render-html="list.author.nickName"></span> </a> 在
                        <span class="addr" render-html="list.place.name"></span>

                    </p>
                    <p>
                        <i class="fa fa-eye fa-fw"></i>
                        <span render-html="list.viewCount"></span>
                        <i class="fa fa-commenting fa-fw"></i>
                        <span render-html="list.commentCount"></span>
                    </p>
                </div>
                <div class="col bigimg">
                    <a name="targetA" data-href="travelContent.html?id=" render-key="list.id" render-fun="getAddress">
                        <img render-src="list.coverUrl">
                    </a>
                </div>
            </div>

        </div>
    </div>
</div>


</body>

</html>